#include "Rectangle.h"
#include "MathRuleConstant.h" 

using namespace MathRuleConstant;

Rectangle::Rectangle(double len, double width) : 
   length_m(MathRuleConstant::roundSmall(len)),
   width_m(MathRuleConstant::roundSmall(width))  
{
}

bool Rectangle::valid() const
{
  return checkRange(length_m,MINLENGTH,false,MAXLENGTH,true) && 
         checkRange(width_m,MINWIDTH,false,MAXWIDTH,false); 
}

bool Rectangle::checkNewShape(double& len, double& width) const
{
  len = roundSmall(len);
  width = roundSmall(width); 
  return checkRange(len,MINLENGTH,false,MAXLENGTH,true) &&
         checkRange(width,MINWIDTH,false,MAXWIDTH,false);
}

void Rectangle::changeShape(double len, double width)
{
  if (checkNewShape(len,width))
  {
    length_m = len;
    width_m = width;
  }
}

double Rectangle::getArea() const
{
  return valid() ? roundBig(length_m*width_m) : 0;
}

double Rectangle::getPerimeter() const
{
  return valid() ? 2*(length_m+width_m) : 0;
}

